﻿using MXERP.Shared.Extensions;
using MXERP.Shared.Wrapper;

namespace MXERP.Client.Application.Extensions
{
    internal static class ResultExtension
    {
        internal static async Task<ApiResponse<T>> ToResult<T>(this HttpResponseMessage response) where T : class
        {
            var responseAsString = await response.Content.ReadAsStringAsync();
            return responseAsString.ToEntity<ApiResponse<T>>();
        }

        internal static async Task<ApiResponse> ToResult(this HttpResponseMessage response)
        {
            var responseAsString = await response.Content.ReadAsStringAsync();
            return responseAsString.ToEntity<ApiResponse>();
        }

        internal static async Task<PageResponse<ApiResponse<T>>> ToPaginatedResult<T>(this HttpResponseMessage response) where T : class
        {
            var responseAsString = await response.Content.ReadAsStringAsync();
            return responseAsString.ToEntity<PageResponse<ApiResponse<T>>>();
        }
    }
}
